package org.hzy.dao.impl;

import java.math.BigDecimal;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.hzy.dao.IEmpDao;
import org.hzy.entity.Emp;

public class EmpDaoImpl extends BaseDao<Emp> implements IEmpDao{
	public Integer getCount(){
		Query query=super.getSession().createSQLQuery("select count(1) from scott.emp");
		BigDecimal i=(BigDecimal)query.uniqueResult();
		return (Integer) i.intValue();
	}
	
	public List findAllByPage(Integer start,Integer limit){
		SQLQuery query=(SQLQuery)super.getSession().createSQLQuery("select empno,ename,to_char(hiredate,'hh:mm:ss') as hiredate from (select e.*,rownum rn from (select * from scott.emp ) e where rownum <=?) e1 where rn>?");
		query.setString(0, (start+limit)+"");
		query.setString(1, start+"");
		
//		SQLQuery query=(SQLQuery) super.getSession().createSQLQuery("select hiredate from scott.emp");
//		query.addScalar("empno", Hibernate.INTEGER);
//		query.addScalar("ename", Hibernate.STRING);
//		query.addScalar("hiredate",Hibernate.DATE);
//		Query query=super.getSession().createQuery("from Emp");
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		
		return query.list();
	}
}
